package com.tianyadu.multi_module_demo.controller;

import com.tianyadu.multi_module_demo.domain.User;
import com.tianyadu.multi_module_demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @FileName: UserController
 * @Description: 用户控制类
 * @author: xueyj
 * @create: 2018-11-17 10:12
 */
@RestController
@RequestMapping("/user")
public class UserController {


    private final UserRepository userRepository;

    @Autowired
    public UserController(UserRepository userRepository){
        this.userRepository = userRepository;
    }

    /**
      * @Description: 保存用户信息
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/17 10:17
      */
    @PostMapping("/save")
    public User saveUser(@RequestParam String name) {
        User user = new User();
        user.setName(name);
        if (userRepository.saveUser(user)) {
            System.out.printf("用户信息：%s 保存成功！\n",user);
        }
        return user;
    }
}